double waypt_speed(const Waypoint* A, const Waypoint* B);
double waypt_speed_ex(const Waypoint* A, const Waypoint* B);
double waypt_vertical_speed(const Waypoint* A, const Waypoint* B);
+double waypt_gradient(const Waypoint* A, const Waypoint* B);
double waypt_course(const Waypoint* A, const Waypoint* B);
double waypt_distance(const Waypoint* A, const Waypoint* B);
double waypt_distance_ex(const Waypoint* A, const Waypoint* B);
static gbfile* fout;
static const Waypoint* prevwpp;
static double vspeed;
+static double gradient;
/* internal helper functions */
case 'v':
gbfprintf(fout, "%2.2f", vspeed);
break;
+ case 'g':
+ gbfprintf(fout, "%2.1f%%", gradient);
+ break;
case 't':
{
QTime t = prevwpp->GetCreationTime().toUTC().time();
if (prevwpp) {
subrip_prevwp_pr(waypointp);
vspeed = waypt_vertical_speed(waypointp, prevwpp);
+ gradient = waypt_gradient(waypointp, prevwpp);
}
prevwpp = waypointp;
}
prevwpp = NULL;
vspeed = 0;
+ gradient = 0;
if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) {
time(&gpstime_t);
}
}
+/*
+ * Returns "Road Gradient" between A and B as a percentage of slope.
+ * If there is no distance or either A or B have unknown altitude, return 0.
+ */
+double
+waypt_gradient(const Waypoint* A, const Waypoint* B)
+{
+ double dist, altitude, gradient;
+ dist = waypt_distance(A, B);
+ if (dist == 0) {
+ return 0;
+ }
+
+ altitude = A->altitude - B->altitude;
+ if (altitude == 0 ||
+ A->altitude == unknown _alt || B->altitude == unknown_alt) {
+ return 0;
+ }
+
+ gradient = (altitude / dist) * 100;
+ return (gradient);
+}
+
/*
* Calculates "Course True" from A to B
*/
<entry>%h</entry>
<entry>heart rate</entry>
</row>
+<row>
+ <entry>%g</entry>
+ <entry>road gradient</entry>
+</row>
<row>
<entry>\n</entry>
<entry>newline</entry>